home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / util / blank / bserver_v14.lha / BServer_v1.4 / Sources.lha / Sources / clients / FadeScreen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-23  |  4.8 KB  |  234 lines

  1. ; /*
  2. sc RESOPT IGNORE=73 DATA=NEAR NMINC UCHAR CONSTLIB STREQ STRMERGE NOSTKCHK NOSTDIO OPTIMIZE OPTSIZE fadescreen.c
  3. slink from lib:c.o fadescreen.o to //Clients/FadeScreen lib /lib/client.lib lib:sc.lib lib:amiga.lib SC SD STRIPDEBUG NOICONS
  4. delete fadescreen.o
  5. quit
  6.  
  7.  FadeScreen 1.3  (Client for BServer)
  8.  
  9.  Copyright © 1994-1995 Stefano Reksten of 3AM - The Three Amigos!!!
  10.  All rights reserved.
  11. */
  12.  
  13. #include <exec/memory.h>
  14. #include <intuition/intuition.h>
  15. #include <intuition/intuitionbase.h>
  16. #include <graphics/gfxbase.h>
  17.  
  18. #include <proto/exec.h>
  19. #include <proto/graphics.h>
  20. #include <proto/icon.h>
  21. #include <stdlib.h>
  22.  
  23. #include "/include/client.h"
  24.  
  25. char *ver = "$VER: FadeScreen 1.3 "__AMIGADATE__;
  26.  
  27. struct IntuitionBase *IntuitionBase;
  28. struct GfxBase *GfxBase;
  29. struct Library *BitMapBase, *IconBase;
  30.  
  31. struct Screen *scr;
  32. UWORD scrdepth, darkness_percent;
  33.  
  34. struct DisplayIDInformation *dinfo;
  35. ULONG command;
  36.  
  37.  
  38. UWORD GetDarknessPercent( void )
  39. {
  40. struct DiskObject *dobj;
  41. char **ttypes;
  42. char *pstr;
  43. UWORD percent = 0;
  44.  
  45. if ( IconBase = OpenLibrary( "icon.library", 0L ) )
  46.     {
  47.     if ( dobj = GetDiskObject( "FadeScreen" ) )
  48.         {
  49.         ttypes = dobj->do_ToolTypes;
  50.  
  51.         if ( pstr = FindToolType( ttypes, "BRIGHTNESS" ) )
  52.             percent = atoi( pstr );
  53.  
  54.         FreeDiskObject( dobj );
  55.         }
  56.     CloseLibrary( IconBase );
  57.     }
  58. return percent;
  59. }
  60.  
  61.  
  62. void FadeOut( void )
  63. {
  64. UWORD n;
  65. ULONG color;
  66. BOOL still_fading, blanking;
  67. ULONG *current, *colors, *copy_of_colors, *faded, colorsize = (257 * 3 + 1) * sizeof(ULONG);
  68. ULONG r, g, b;
  69. BOOL result = FALSE;
  70. UBYTE fadecount = 0;
  71.  
  72. scr = IntuitionBase->FirstScreen;
  73. scrdepth = scr->RastPort.BitMap->Depth;
  74.  
  75. if ( colors = AllocVec( colorsize, MEMF_ANY|MEMF_CLEAR ) )
  76.     {
  77.     if ( faded = AllocVec( colorsize, MEMF_ANY|MEMF_CLEAR ) )
  78.         {
  79.         if ( CheckAA() )
  80.             {
  81.             current = colors;
  82.             current++;
  83.             GetRGB32( scr->ViewPort.ColorMap, 0, 1<<scrdepth, current );
  84.             *colors = (1L<<scrdepth)<<16;
  85.             CopyMem( colors, faded, colorsize );
  86.             }
  87.         else
  88.             {
  89.             current = colors;
  90.             current++;
  91.             for ( n = 0; n < 1<<scrdepth; n++ )
  92.                 {
  93.                 color = GetRGB4( scr->ViewPort.ColorMap, n );
  94.                 *current++ = color >> 8;
  95.                 *current++ = (color & 0xF0) >> 4;
  96.                 *current++ = color & 0xF;
  97.                 CopyMem( colors, faded, colorsize );
  98.                 }
  99.             }
  100.  
  101.         result = TRUE;
  102.         SpritesOff();
  103.  
  104.         blanking = TRUE;
  105.         still_fading = TRUE;
  106.  
  107.         while( blanking )
  108.             {
  109.             if ( still_fading )
  110.                 command = GetServerCommand();
  111.             else
  112.                 command = WaitServerCommand();
  113.  
  114.             if ( command == COMMAND_QUIT )
  115.                 blanking = FALSE;
  116.             else
  117.             if ( still_fading )
  118.                 {
  119.                 current = faded;
  120.                 current++;
  121.                 copy_of_colors = colors;
  122.                 copy_of_colors++;
  123.  
  124.                 still_fading = FALSE;
  125.                 if ( CheckAA() )
  126.                     {
  127.                     for ( n = 0; n < 1<<scrdepth; n++ )
  128.                         {
  129.                         if ( *current>>24 > (*copy_of_colors++>>24)*darkness_percent/100 )
  130.                             {
  131.                             still_fading = TRUE;
  132.                             *current -= 0x01000000;
  133.                             }
  134.                         current++;
  135.                         if ( *current>>24 > (*copy_of_colors++>>24)*darkness_percent/100 )
  136.                             {
  137.                             still_fading = TRUE;
  138.                             *current -= 0x01000000;
  139.                             }
  140.                         current++;
  141.                         if ( *current>>24 > (*copy_of_colors++>>24)*darkness_percent/100 )
  142.                             {
  143.                             still_fading = TRUE;
  144.                             *current -= 0x01000000;
  145.                             }
  146.                         current++;
  147.                         }
  148.  
  149.                     WaitTOF();
  150.                     LoadRGB32( &scr->ViewPort, faded );
  151.                     }
  152.                 else
  153.                     {
  154.                     WaitTOF();
  155.                     if ( ++fadecount == 16 )
  156.                         {
  157.                         fadecount = 0;
  158.                         for ( n = 0; n < 1<<scrdepth; n++ )
  159.                             {
  160.                             if ( *current > (*copy_of_colors++)*darkness_percent/100 )
  161.                                 {
  162.                                 *current -= 0x01;
  163.                                 still_fading = TRUE;
  164.                                 }
  165.                             r = *current++;
  166.  
  167.                             if ( *current > (*copy_of_colors++)*darkness_percent/100 )
  168.                                 {
  169.                                 *current -= 0x01;
  170.                                 still_fading = TRUE;
  171.                                 }
  172.                             g = *current++;
  173.  
  174.                             if ( *current > (*copy_of_colors++)*darkness_percent/100 )
  175.                                 {
  176.                                 *current -= 0x01;
  177.                                 still_fading = TRUE;
  178.                                 }
  179.                             b = *current++;
  180.  
  181.                             SetRGB4( &scr->ViewPort, n, r, g, b );
  182.                             }
  183.                         }
  184.                     else still_fading = TRUE;
  185.                     }
  186.                 }
  187.             }
  188.  
  189.         SpritesOn();
  190.  
  191.         if ( CheckAA() )
  192.             LoadRGB32( &scr->ViewPort, colors );
  193.         else
  194.             {
  195.             current = colors;
  196.             current++;
  197.             for ( n = 0; n < 1<<scrdepth; n++ )
  198.                 {
  199.                 r = *current++;
  200.                 g = *current++;
  201.                 b = *current++;
  202.                 SetRGB4( &scr->ViewPort, n, r, g, b );
  203.                 }
  204.             }
  205.  
  206.         FreeVec( faded );
  207.         }
  208.     FreeVec( colors );
  209.     }
  210.  
  211. if ( !result )
  212.     SendClientMsg( ACTION_FAILED );
  213. }
  214.  
  215.  
  216. void __main( char *line )
  217. {
  218. if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 36L ) )
  219.     {
  220.     if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library",0L ) )
  221.         {
  222.         if ( dinfo = OpenCommunication() )
  223.             {
  224.             darkness_percent = GetDarknessPercent();
  225.  
  226.             FadeOut();
  227.             CloseCommunication( dinfo );
  228.             }
  229.         CloseLibrary( (struct Library *)GfxBase );
  230.         }
  231.     CloseLibrary( (struct Library *)IntuitionBase );
  232.     }
  233. }
  234.